package com.shopping;
public class Product {
    private String name;
    private String category;
    private double price;
    private int stock;
    private int numberInCart;
    public Product(String name, String category, double price, int stock) {
        this.name = name;
        this.category = category;
        this.price = price;
        this.stock = stock;
        this.numberInCart = 0;
    }
    public String getName() {
        return name;
    }
    public String getCategory() {
        return category;
    }
    public double getPrice() {
        return price;
    }
    public int getStock() {
        return stock;
    }
    public int getnumberInCart() {
        return numberInCart;
    }
    public void setNumberInCart(int numberInCart) {
        if (numberInCart <= stock) {
            this.numberInCart = numberInCart;
        } else {
            System.out.println("库存不足，无法添加更多！");
        }
    }
    public String toString() {
        return "Product{" +
                "name='" + name + '\'' +
                ", category='" + category + '\'' +
                ", price=" + price +
                ", stock=" + stock +
                ", quantityInCart=" + numberInCart +
                '}';
    }
}